﻿using System;
using TestingConcurrencyBenchmark.Helpers;

namespace TestingConcurrencyBenchmark.Problems.ReadersWriters
{
    class ReaderWriterWithRaceCondition:IReaderWriter
    {
        private readonly BenchmarkSemaphore _writerMutex;

        public ReaderWriterWithRaceCondition()
        {
            _writerMutex = new BenchmarkSemaphore(1);
        }

        #region IReaderWriter Members

        public void Write(Action action)
        {
            _writerMutex.WaitOne();
            action();
            _writerMutex.Release();
        }

        public void Read(Action action)
        {
            action();
        }

        #endregion
    }
}
